package consts

var HTTPSuccess = New(200, 0, "OK")                          // Success
var HTTPBadRequest = New(400, 51, "请求参数错误")                  // Bad Request
var HTTPUnauthorized = New(401, 0, "用户认证失败")                 // Unauthorized
var HTTPForbidden = New(403, 0, "服务器理解请求客户端的请求，但是拒绝执行此请求")   // Forbidden
var HTTPNotFound = New(404, 0, "没有该请求")                      // Not Found
var HTTPMethodNotAllowed = New(405, 0, "请求中的方法被禁止")          // Method Not Allowed
var HTTPInternalServer = New(500, 0, "服务器内部错误")              // Internal Server Error
var HTTPNotImplemented = New(501, 0, "请求方法错误")               // Not Implemented
var HTTPBadGateway = New(502, 0, "接收到了一个无效的响应")              // Bad Gateway
var HTTPServiceUnavailable = New(503, 0, "服务器暂时的无法处理客户端的请求") // Service Unavailable
var HTTPGatewayTimeOut = New(504, 0, "未及时从远端服务器获取请求")        // Gateway Time-out
var HTTPVersionError = New(505, 0, "服务器不支持请求的HTTP协议的版本")     //Version Error
var HTTPInternalError = New(1050, 50, "空指针异常")               //Version Error
var HTTPCodeMap = [...]BizCode{HTTPInternalError, HTTPSuccess, HTTPBadRequest, HTTPUnauthorized, HTTPForbidden, HTTPNotFound, HTTPMethodNotAllowed, HTTPInternalServer, HTTPNotImplemented, HTTPBadGateway, HTTPServiceUnavailable, HTTPGatewayTimeOut, HTTPVersionError}

type BizCode struct {
	code    int    // 错误码
	sysCode int    // goFrame系统错误码
	message string // 错误描述
}

// Code 获取错误码
func (c BizCode) Code() int {
	return c.code
}

func (c BizCode) Message() string {
	return c.message
}

func (c BizCode) SysCode() int {
	return c.sysCode
}

func New(code int, sysCode int, message string) BizCode {
	return BizCode{
		code:    code,
		sysCode: sysCode,
		message: message,
	}
}
